package com.zing.mapper;

import com.github.pagehelper.Page;
import com.zing.annotation.AutoFill;
import com.zing.dto.DishPageQueryDTO;
import com.zing.entity.Dish;
import com.zing.enumeration.OperationType;
import com.zing.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    // 根据分类id查询菜品数量
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    //新增菜品
    @AutoFill(value= OperationType.INSERT)
    void insert(Dish dish);

    //分页查询菜品
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    //根据id查询菜品
    @Select("select * from dish where id=#{id}")
    Dish getById(Long id);

    //根据id删除菜品
    @Delete("delete from dish where id = #{id}")
    void deleteById(Long id);

    //更新菜品
    @AutoFill(value= OperationType.UPDATE)
    void update(Dish dish);

    // 动态条件查询菜品
    List<Dish> list(Dish dish);

    // 根据套餐id查询菜品
    @Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long setmealId);

    // 统计不同状态菜品数
    @Select("select count(id) from dish d where status = ${status}")
    Integer countByStatus(Integer status);
}
